<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
  <meta name="description" content="">
  <meta name="author" content="">
  <link rel="icon" href="../../resources/ico/favicon.ico">

  <title>Register</title>

  <link rel="stylesheet" href="../../resources/css/lib/bootstrap.min.css">

  <!-- Custom styles for this template -->
  <link href="../../resources/css/login.css" rel="stylesheet">
  <script src="../../resources/js/jquery-3.3.1.min.js"></script>
  <style type="text/css">
    #formPos{
      position: absolute;
      top: 25%;
      left: 25%;
      width: 50%;
      height: 50%;
    }
  </style>

  <script>
    $(document).ready(function () {
      $("#errorInf").hide();
      $("#submit").click(function () {
        var params = {};
        params.username = $("#username").val();
        params.password = $("#password").val();
        params.email=$("#email").val();
        $.ajax({
          type: "POST",
          url: "register",//注意路径
          data: params,
          dataType: "json",
          success: function (data) {
            if(data.result==="SUCCESS"){

              var len=document.location.href.length;
              document.location.href=document.location.href.substr(0,len-8)+params.username;
            }
            else{
              $("#errorInf").show();
            }
          },
          error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest.status);
            alert(XMLHttpRequest.readyState);
            alert(textStatus);
          }
        });
      });
    });
  </script>

</head>
<body>
<div class="container">

  <nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
      <div class="navbar-header">
        <a class="navbar-brand">
          Register
        </a>
      </div>
      <div id="navbar" class="navbar-collapse collapse">
        <ul class="nav navbar-nav navbar-right">
          <li><a href="/exit">Back</a></li>
        </ul>
      </div>
    </div>
  </nav>


  <div id="formPos">
    <form class="form-signin">
      <div id="errorInf" style="color: red; font-size: medium; font-family: Arial">Username or Email has been registered!</div>
      <h2 class="form-signin-heading">Please Register</h2>
      <label for="email" class="sr-only">Email address</label>
      <input type="email" id="email" class="form-control" placeholder="Email address" required autofocus>
      <label for="username" class="sr-only">User name</label>
      <input type="text" id="username" class="form-control" placeholder="User name" required autofocus>
      <label for="password" class="sr-only">Password</label>
      <input type="password" id="password" class="form-control" placeholder="Password" required>
      <button class="btn btn-lg btn-primary btn-block" id="submit" type="button">Register</button>
    </form>
  </div>
</div><!-- /container -->
</body>
</html>
